package cnsukidayo.com.gitee.controller.content;

import cnsukidayo.com.gitee.model.params.*;
import cnsukidayo.com.gitee.model.pojo.Pet;
import cnsukidayo.com.gitee.model.support.BaseResponse;
import cnsukidayo.com.gitee.model.vo.PetShelterVO;
import cnsukidayo.com.gitee.service.PetShelterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author sukidayo
 * @date: 2023/3/13 14:23
 */
@RestController("ContentPetShelterController")
@RequestMapping("/content/petshelter")
public class PetShelterController {

    private final PetShelterService petShelterService;

    public PetShelterController(PetShelterService petShelterService) {
        this.petShelterService = petShelterService;
    }

    @ApiOperation("收留宠物")
    @PostMapping("addPetToShelter")
    public void addPetToShelter(@RequestBody @Validated CreatePetParam createPetParam, HttpServletRequest httpServletRequest) {
        petShelterService.addPetToShelter(createPetParam.getId(), createPetParam);
    }

    @ApiOperation("创建宠物收留所")
    @PostMapping(value = "createPetShelter")
    public BaseResponse<String> createPetShelter(@RequestBody @Validated CreatePetShelterParam createPetStoreParam) {
        petShelterService.createPetShelter(createPetStoreParam);
        return BaseResponse.ok("用户创建成功!");
    }

    @ApiOperation("查询所有宠物收留所")
    @PostMapping(value = "queryPetShelterWithPage")
    public List<PetShelterVO> queryPetShelterWithPage(@RequestBody @Validated QueryPageParam queryPageParam) {
        return petShelterService.queryPetShelterWithPage(queryPageParam);
    }

    @ApiOperation("查询某个收留所旗下的所有宠物")
    @PostMapping(value = "queryPetFromShelter")
    public List<Pet> queryPetFromShelter(@RequestBody @Validated PetQueryPageParam petQueryPageParam) {
        return petShelterService.queryPetWithPage(petQueryPageParam);
    }

    @ApiOperation("查询宠物日志")
    @PostMapping(value = "queryPetLog")
    public BaseResponse<String> queryPetLog(@RequestBody @Validated QueryPetLogParam queryPetLogParam) {
        return new BaseResponse<>(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), petShelterService.queryPetLog(queryPetLogParam));
    }

}
